import HttpUtils from '../HttpUtils/HttpUtils';
// 获取当前时间戳
var timestamp = Date.parse(new Date()) / 1000;
Page({
	...HttpUtils.func,
	data: {
		noData: "noData",   //noData无数据     noDataHide 展示数据
		keyword: '',
		contentType: 'Video',
		pageIndex: '1',
		pageItems: '10',
		showVideo: true,		 //是否展示栏目列表
		showData: false,  	//无数据
	},
	onLoad(params) {
		this.setData({
			keyword: params.keyword,
		})
		this.LoadVideoSearch();
	},

	//点击键盘完成
	searchSubmit(event) {
		this.setData({
			keyword: event.detail.value,
		})
		this.LoadVideoSearch();
	},
 
	//视频搜索
	LoadVideoSearch(event) {
		var newUrl = getApp().globalData.dangjianUrl + "/content/contentSearch";
		var params = {};
		params["keyword"] = this.data.keyword + "";
		params["siteCode"] = getApp().globalData.siteCode + "";
		params["pageIndex"] = this.data.pageIndex + "";
		params["pageItems"] = this.data.pageItems + "";
		params["contentType"] = this.data.contentType + "";
		params = JSON.stringify(params);
		this.httpGet(newUrl, params, "视频搜索加载失败").then(
			(respData) => {
				var result = respData.data.result.code;
				if (1 == result) {
					if (respData.data.contents.content.length > 0) {
						var contents = respData.data.contents;
						var totalPages = contents.totalPages;
						var pageIndex = contents.pageIndex;
						contents = contents.content;
						var contentList = [];
						for (var index in contents) {
							var content = contents[index];
							var json = {};
							var thumbnail = content.thumbnail;
							if (null == thumbnail || "" == thumbnail) {
								var imageFiles = content.imageFiles;
								for (var j in imageFiles) {
									thumbnail = imageFiles[j].url;
									break;
								}
							}
							json["name"] = content.name;
							json["publishTime"] = content.publishTime;
							json["url"] = thumbnail;
							json["code"] = content.code;
							json["type"] = content.type;
							json["count"] = content.count;
							json["sourceFrom"] = null == content.sourceFrom ? "华数" : content.sourceFrom;
							contentList.push(json);
						}
						this.setData({
							"contentList": contentList,
							"pageIndex": pageIndex,
							"totalPages": totalPages,
							'showData': false,
							'showVideo': true,
						});
					} else {
						this.setData({
							'showVideo': false,
							'showData': true,
						})
					}
				} else {
					dd.alert({ title: respData.data.result.description });
				}
			}
		);
	},

	//视频详情
	articleDetail(e) {
		var folderCode = e.currentTarget.dataset.foldercode;
		var type = e.currentTarget.dataset.type;
		var code = e.currentTarget.dataset.code;
		var name = e.currentTarget.dataset.name;
		var detailUrl = this.getUrl(type, code, folderCode, name);
		if (detailUrl.length > 0) {
			dd.navigateTo({
				url: detailUrl
			});
		} else {
			this.showPageMsg("tips", "该内容类型详情页暂未开发");
		}
	},
});
